package com.groot.medical.service;

import java.util.List;

import com.groot.medical.dao.MenuDao;
import com.groot.medical.dao.MenuDaoImpl;
import com.groot.medical.entity.Menu;
import com.groot.medical.entity.PageBean;

public class MenuServiceImpl implements MenuService {
	private MenuDao menuDao = new MenuDaoImpl();
	@Override
	public int addMenu(Menu menu) {
		//查询当前最大的菜单编号
		int maxMenuId = menuDao.findMaxMenuId();
		int index = maxMenuId+1;
		menu.setMenuId(String.valueOf(index));
		return menuDao.addMenu(menu);
	}
	@Override
	public List<Menu> findAllMenuLsit() {
		List<Menu> menuList = menuDao.findAllMenuList();
		return menuList;
	}
	@Override
	public List<Menu> getMenuByUserId(String userId) {
		List<Menu> menuList = menuDao.findMenuListById(userId);
		return menuList;
	}
	@Override
	public List<Menu> findMenuByRoleId(String roleid) {
		List<Menu> roleMenuList = menuDao.findMenuByRoleId(roleid);
		return roleMenuList;
	}
	@Override
	public int delMenuByRoleId(String roleid) {
		int del = menuDao.delMenuByRoleId(roleid);
		return del;
	}
	@SuppressWarnings("unused")
	@Override
	public PageBean<Menu> findByPage(int pageNum, int pageSize) {
		//获取记录总条数
		int totalRecord = menuDao.getAllMenuCount();
		@SuppressWarnings("rawtypes")
		PageBean pegeBean = new PageBean<>(pageNum, pageSize, totalRecord);
		int startIndex = pegeBean.getStartIndex();
		pegeBean.setList(menuDao.findMenuByPage(startIndex,pageSize));
		return pegeBean;
	}
	@Override
	public Menu findMenuByMenuId(String menuid) {
		Menu menu  = menuDao.findMenuByMenuId(menuid);
		return menu;
	}
	@Override
	public void editMenu(Menu menu) {
		menuDao.editMenu(menu);
		
	}

}
